function [sub_bin, sub_N_bin]=calc_sub_bin(N_i, A_t, P_t, PIns0_t, PIns_t,Sunit_state, Scost_state, Skwh_state)

global tract_state_xxwalk_mat ntract
global  tl_global Sunit_tg Scost_tg Skwh_tg

Sunit_t= sum(tract_state_xxwalk_mat.*(ones(ntract,1)*Sunit_state'),2);
Scost_t= sum(tract_state_xxwalk_mat.*(ones(ntract,1)*Scost_state'),2);
Skwh_t= sum(tract_state_xxwalk_mat.*(ones(ntract,1)*Skwh_state'),2);

if tl_global==1
    Sunit_t= Sunit_tg;
    Scost_t= Scost_tg;
    Skwh_t= Skwh_tg;
end

sub_bin=N_i.*A_t.*(Skwh_t)+Scost_t.*(PIns0_t+ PIns_t.*N_i)+N_i.*Sunit_t;

sub_N_bin=A_t.*(Skwh_t)+Scost_t.*( PIns_t)+Sunit_t;